use statarep_2013_07_29.dta, clear


***
* Manip Check
***
bysort treatment: su mancheck*

forvalues i=1(1)4 {
	di "Manipulation Check 1, Treatment `i'"
	su mancheck_1 if treatment==`i'
	di (r(mean)-0.33)/(((r(mean)-(1-r(mean)))/r(N))^(1/2))
	di "Manipulation Check 2, Treatment `i'"
	su mancheck_2 if treatment==`i'
	di (r(mean)-0.25)/(((r(mean)-(1-r(mean)))/r(N))^(1/2))
	}
*
forvalues i=1(1)4 {
	di "Test Manipulation Check 1, Treatment `i'"
	bitest mancheck_1 = 0.33 if treatment==`i'
	di "Test Manipulation Check 2, Treatment `i'"
	bitest mancheck_2 = 0.25 if treatment==`i'
	}

***
* Exchangability/Balance Tests
***

* Variable lists
global intro_vars "age male race_white race_black race_hisp race_asian married_dum college_dum"
global other_vars "pk_sum iso_standard ethno_standard"
*global demogr_vars "working ab_med_income repub_dum conserv_dum taxes_dum union_dum inequal_dum"
global demogr_vars "working ab_med_income repub_dum conserv_dum union_dum"

* MLogit, nothing significant except for male, ilaw
*mlogit treatment $intro_vars $other_vars $demogr_vars
*mlogit treatment $intro_vars


* Chi2 test
* All covariates, pre and post treatment
mat drop _all
		quietly logit tmt_ilaw $intro_vars $other_vars $demogr_vars
		est2vec balance_all, vars($intro_vars $other_vars $demogr_vars) e(chi2 p r2_p) replace
	foreach t in tmt_econ tmt_null tmt_plac {
		quietly logit `t' $intro_vars $other_vars $demogr_vars
		est2vec balance_`t', addto(balance_all) name(`t') replace
		}
	est2tex balance_all, preserve path("C:\WTO_Survey\Drafts\") mark(stars) fancy replace

* Pre treatment covariates only
mat drop _all
		quietly logit tmt_ilaw $intro_vars
		est2vec balance_pt, vars($intro_vars) e(chi2 p r2_p) replace
	foreach t in tmt_econ tmt_null tmt_plac {
		quietly logit `t' $intro_vars
		est2vec balance_`t', addto(balance_pt) name(`t') replace
		}
	est2tex balance_pt, preserve path("C:\WTO_Survey\Drafts\") mark(stars) fancy replace
*

* Possible treatment effects on trade policy response- not strong contamination
*reg protect tmt_ilaw tmt_econ tmt_plac
ologit tradecateg tmt_ilaw tmt_econ tmt_plac
est2vec contam, vars(tmt_ilaw tmt_econ tmt_plac) e(chi2 p r2_p) replace
	est2tex contam, preserve path("C:\WTO_Survey\Drafts\") mark(stars) fancy replace


mlogit tradecateg tmt_ilaw tmt_econ tmt_plac


***
* Treatment Effects
***
reg approve_dum tmt_ilaw tmt_econ tmt_plac

* This makes main treatment table, Table 1
bysort treatment: su approve_dum
* Difference in means
reg approve_dum tmt_ilaw if treatment==1 | treatment == 3
reg approve_dum tmt_econ if treatment==2 | treatment == 3
reg approve_dum tmt_plac if treatment==4 | treatment == 3


***
* Treatment Effects | Expressed Trade Policy Preferences
***
bysort protect: reg approve_dum tmt_ilaw tmt_econ tmt_plac
bysort freetrade: reg approve_dum tmt_ilaw tmt_econ tmt_plac
* NO OPINION is where all the treatment effect is!
bysort notradeopin: reg approve_dum tmt_ilaw tmt_econ tmt_plac
*
bysort tradepol:  reg approve_dum tmt_ilaw tmt_econ tmt_plac
bysort tradecateg:  reg approve_dum tmt_ilaw tmt_econ tmt_plac if tradepol!=.

*** This creates the treatment effects table broken down by preferences
* Table 2
* Difference in means, international law, broken down by preferences
	forvalues i = 1(1)3 {
	preserve
	keep if tradecateg==`i'
		foreach t in ilaw econ null plac {
			su approve_dum if tmt_`t'==1
			}
	reg approve_dum tmt_ilaw if treatment==1 | treatment == 3
	restore
	}
*
* Difference in means, econ, broken down by preferences
	forvalues i = 1(1)3 {
	preserve
	keep if tradecateg==`i'
	reg approve_dum tmt_econ if treatment==2 | treatment == 3
	restore
	}
*	
* Difference in means, placebo, broken down by preferences
	forvalues i = 1(1)3 {
	preserve
	keep if tradecateg==`i'
	reg approve_dum tmt_plac if treatment==4 | treatment == 3
	restore
	}
*

* Ilaw vs Placebo for tradecateg==2
preserve
keep if tradecateg==2
keep if treatment==1 | treatment==4
reg approve_dum tmt_ilaw
restore



***
* R1 Suggestions
*	Regressions broken down by certain covariates
***
cd "C:\WTO_Survey\Analysis\"
use working_070412.dta, clear

gen abovemeanage=.
replace abovemeanage=1 if age>49
replace abovemeanage=0 if age<=49

gen abovemedage=.
replace abovemedage=1 if age>29
replace abovemedage=0 if age<=29


preserve
drop if abovemeanage==.
drop if tradecateg==.
bysort abovemeanage tradecateg: reg approve_dum tmt_ilaw if treatment==1 | treatment == 3
restore

preserve
drop if abovemedage==.
drop if tradecateg==.
bysort abovemedage tradecateg: reg approve_dum tmt_ilaw if treatment==1 | treatment == 3
restore

preserve
drop if tradecateg==.
bysort repub_dum tradecateg: reg approve_dum tmt_ilaw if treatment==1 | treatment == 3
restore

gen i1 = abovemedage*tmt_ilaw
bysort tradecateg: reg approve_dum tmt_ilaw abovemedage i1 if (treatment==1 | treatment==3)

***
* R2 Suggestions
*	Regression with full battery of controls
***
global intro_vars "age male race_white race_black race_hisp race_asian married_dum college_dum"
global other_vars "pk_sum iso_standard ethno_standard"
*global demogr_vars "working ab_med_income repub_dum conserv_dum taxes_dum union_dum inequal_dum"
global demogr_vars "working ab_med_income repub_dum conserv_dum union_dum"

reg approve_dum tmt_ilaw tmt_econ tmt_plac  $intro_vars $other_vars $demogr_vars if tradepol!=. & tradecateg==1
	est2vec ft, vars(tmt_ilaw tmt_econ tmt_plac  $intro_vars $other_vars $demogr_vars) replace e(r2 F)
reg approve_dum tmt_ilaw tmt_econ tmt_plac  $intro_vars $other_vars $demogr_vars if tradepol!=. & tradecateg==2
	est2vec noop, addto(ft) name(noop)
reg approve_dum tmt_ilaw tmt_econ tmt_plac  $intro_vars $other_vars $demogr_vars if tradepol!=. & tradecateg==3
	est2vec prot, addto(ft) name(prot)
est2tex ft, preserve path("C:\WTO_Survey\Drafts\") mark(stars) fancy replace

reg approve_dum $intro_vars $other_vars $demogr_vars
	est2vec ftfull, vars($intro_vars $other_vars $demogr_vars) replace e(r2 F)
probit approve_dum $intro_vars $other_vars $demogr_vars
	est2vec probitfull, addto(ftfull) name(probit)
est2tex ftfull, preserve path("C:\WTO_Survey\Drafts\") mark(stars) fancy replace


